package org.ala.tcp_feign_common.enums;

import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 消息类型
 * 
 * @author 骆毅(ala)
 * @date 2024年4月18日
 */
public enum TcpFeignMessageTypeEnums {

	LOGIN((byte)1, "login", "登录消息"),
	LOGIN_ACK((byte)2, "login_ack", "登录回执"),
	
	HEART((byte)3, "heart", "心跳消息"),
	HEART_ACK((byte)4, "heart_ack", "心跳回执"),
	
	BIZ((byte)5, "biz", "业务消息"),
	BIZ_ACK((byte)6, "biz_ack", "业务回执"),
	
	BIZ_RESP((byte)7, "biz_resp", "业务返回结果"),
	BIZ_RESP_ACK((byte)8, "biz_resp_ack", "业务返回结果回执"),
	
	CLOSE((byte)9, "close", "断链消息"),
	CLOSE_ACK((byte)10, "close_ack", "断链回执")
	;
	private byte val;
	private String code;
	private String desc;
	
	private TcpFeignMessageTypeEnums(byte val, String code, String desc) {
		this.val = val;
		this.code = code;
		this.desc = desc;
	}
	
	
	static Map<Byte, TcpFeignMessageTypeEnums> valMapper;
	public static TcpFeignMessageTypeEnums val(byte val) {
		if (valMapper == null) {
			synchronized (TcpFeignMessageTypeEnums.class) {
				if (valMapper == null) {
					valMapper = Arrays.stream(values()).collect(Collectors.toMap(v->v.getVal(), v->v));
				}
			}
		}
		return valMapper.get(val);
	}
	
	
	public byte getVal() {
		return val;
	}
	public void setVal(byte val) {
		this.val = val;
	}
	public String getCode() {
		return code;
	}
	public void setCode(String code) {
		this.code = code;
	}
	public String getDesc() {
		return desc;
	}
	public void setDesc(String desc) {
		this.desc = desc;
	}
}
